<template>
  <!-- <h2>生日提醒</h2> -->
  <workStatistics :todayData="today"></workStatistics>
  <zsearch v-loading="loading">
      <template #title>
        <span>生日提醒</span>
      </template>
      <template #date>
        <el-date-picker
            class="date-1"
            type="date"
            v-model="date"
            placeholder="选择日期">
        </el-date-picker>
      </template>
      <template #select>
        <el-input class="input-1" v-model="name" placeholder="请输入内容"></el-input>
      </template>
      <template #btns>
        <el-button class="btn-1" @click="hanledSearch">查询</el-button>
	      <el-button class="btn-2">导出</el-button>
      </template>
      <template #table>
        <ztable 
          :tableData='data' 
          :strucs='columns'
          :height="'100%'"
          :isshowOperation="true"
        >
        <template #default="slotScope">
          <el-button type="text" class="operation" >短信</el-button>
        </template>
        </ztable>
        
      </template>
      <template #page>
        <zpage 
            :currentPage="current" 
            :total="total"
            :pageSize="size"
            @handleSizeChange="handleSizeChange" 
            @handleCurrentChange="handleCurrentChange"
        ></zpage>
      </template>
    </zsearch>
</template>

<script lang='ts'>
import { defineComponent, reactive, toRefs, ref } from '@vue/runtime-core'

import useRequet, { RespData } from "../../hook/network"

import useConfgin from '../../hook/getconfig'

import ztable from '@components/Table/index.vue'
import zpage from '@components/pagination/pagination.vue'
import zsearch from '@components/search/search.vue'
import workStatistics from "../../components/workStatistics/work.vue"

import { ElMessage } from 'element-plus'

const ID = 501
export default defineComponent({
  name: 'BirthdayTips',
  components: {
    ztable,
    zpage,
    zsearch,
    workStatistics
  },
  setup() {
    let search = reactive({
      date:'',
      name:'',
      current: 1,
      size: 10,
      total: 0,

      loading: false
    })
    let today = reactive({
      todayNewCustomer: 0,
      todayNewSub: 0,
      todayNewCollection: 0,
      todayNewAccessLog: 0,
      todayNewSickMedicalRecords: 0
    })
    const data = ref([])
    // const columns = useConfgin(ID)
    const columns = [
      {
           id: 529,
            name: "",
            viewName: "患者姓名",
            type: 208,
            groupId: 501,
            dataSource: "",
            hint: null,
            defaultValue: null,
            length: null,
            minValue: null,
            maxValue: null,
            rangx: null,
            must: 1,
            errorHit: "",
            value: "",
            orderNum: 1,
            show: 1,
            canUpdate: 0,
            companyId: 1,
            listView: 1,
            insertShow: 1,
            canShow: 1,
            fixed: null,
            idName: null
        },
        {
           id: 529,
            name: "",
            viewName: "病历号",
            type: 208,
            groupId: 501,
            dataSource: "",
            hint: null,
            defaultValue: null,
            length: null,
            minValue: null,
            maxValue: null,
            rangx: null,
            must: 1,
            errorHit: "",
            value: "",
            orderNum: 1,
            show: 1,
            canUpdate: 0,
            companyId: 1,
            listView: 1,
            insertShow: 1,
            canShow: 1,
            fixed: null,
            idName: null
        },
        {
           id: 529,
            name: "",
            viewName: "性别",
            type: 208,
            groupId: 501,
            dataSource: "",
            hint: null,
            defaultValue: null,
            length: null,
            minValue: null,
            maxValue: null,
            rangx: null,
            must: 1,
            errorHit: "",
            value: "",
            orderNum: 1,
            show: 1,
            canUpdate: 0,
            companyId: 1,
            listView: 1,
            insertShow: 1,
            canShow: 1,
            fixed: null,
            idName: null
        },
        {
           id: 529,
            name: "",
            viewName: "出生日期",
            type: 208,
            groupId: 501,
            dataSource: "",
            hint: null,
            defaultValue: null,
            length: null,
            minValue: null,
            maxValue: null,
            rangx: null,
            must: 1,
            errorHit: "",
            value: "",
            orderNum: 1,
            show: 1,
            canUpdate: 0,
            companyId: 1,
            listView: 1,
            insertShow: 1,
            canShow: 1,
            fixed: null,
            idName: null
        },
        {
           id: 529,
            name: "",
            viewName: "年龄",
            type: 208,
            groupId: 501,
            dataSource: "",
            hint: null,
            defaultValue: null,
            length: null,
            minValue: null,
            maxValue: null,
            rangx: null,
            must: 1,
            errorHit: "",
            value: "",
            orderNum: 1,
            show: 1,
            canUpdate: 0,
            companyId: 1,
            listView: 1,
            insertShow: 1,
            canShow: 1,
            fixed: null,
            idName: null
        },
        {
           id: 529,
            name: "createTime",
            viewName: "联系电话",
            type: 208,
            groupId: 501,
            dataSource: "",
            hint: null,
            defaultValue: null,
            length: null,
            minValue: null,
            maxValue: null,
            rangx: null,
            must: 1,
            errorHit: "",
            value: "",
            orderNum: 1,
            show: 1,
            canUpdate: 0,
            companyId: 1,
            listView: 1,
            insertShow: 1,
            canShow: 1,
            fixed: null,
            idName: null
        },
        {
           id: 529,
            name: "",
            viewName: "首诊时间",
            type: 208,
            groupId: 501,
            dataSource: "",
            hint: null,
            defaultValue: null,
            length: null,
            minValue: null,
            maxValue: null,
            rangx: null,
            must: 1,
            errorHit: "",
            value: "",
            orderNum: 1,
            show: 1,
            canUpdate: 0,
            companyId: 1,
            listView: 1,
            insertShow: 1,
            canShow: 1,
            fixed: null,
            idName: null
        },
        {
           id: 529,
            name: "",
            viewName: "主治医生",
            type: 208,
            groupId: 501,
            dataSource: "",
            hint: null,
            defaultValue: null,
            length: null,
            minValue: null,
            maxValue: null,
            rangx: null,
            must: 1,
            errorHit: "",
            value: "",
            orderNum: 1,
            show: 1,
            canUpdate: 0,
            companyId: 1,
            listView: 1,
            insertShow: 1,
            canShow: 1,
            fixed: null,
            idName: null
        },
    ]

    const request = useRequet({ path: "" });

    const req = () => {
      // search.loading = true
      // request.sendRequest({
      //   address: 'inOrderPage',
      //   params: search || {},
      //   success: (resp: RespData) => {
      //     if(resp.code !== 0) return ElMessage.error(resp.msg || '获取失败')
			// 		data.value = resp.data.records
      //     search.total = resp.data.total
      //     search.current = resp.data.current
      //     console.log(data)

      //     search.loading = false
      //   },
      //   fail: (resp: RespData) => {
      //     if(resp.code !== 0) return ElMessage.error(resp.msg || '获取失败')
          
      //   },
      //   method: "POST",
      // })
    }
    req()

    const getTodayStatistics = () => {
      request.sendRequest({
        address: '/pay/order/todayStatistics',
        params: {},
        success: (resp: RespData) => {
          if(resp.code !== 0) return ElMessage.error(resp.msg || '获取失败')
	
          console.log(resp.data)
          today.todayNewCustomer = resp.data.todayNewCustomer
          today.todayNewSub = resp.data.todayNewSub
          today.todayNewCollection = resp.data.todayNewCollection
          today.todayNewAccessLog = resp.data.todayNewAccessLog
          today.todayNewSickMedicalRecords = resp.data.todayNewSickMedicalRecords

          search.loading = false
        },
        fail: (resp: RespData) => {
          if(resp.code !== 0) return ElMessage.error(resp.msg || '获取失败')
          
        },
        method: "POST",
      })
    }
    getTodayStatistics()
    //搜索
    const hanledSearch = () => {
      req()
    }

    // 分页
    const handleCurrentChange = (val: number) => {
			search.current = val
      req()
			console.log('handleCurrentChange', val)
		}
    const handleSizeChange = (val: number) => {
      search.size = val
      req()
			console.log('handleSizeChange', val)
		}
    return {
      data,
      columns,
      ...toRefs(search),
      today,

      handleCurrentChange,
      handleSizeChange,
      hanledSearch
    }
  }
})
</script>
